package com.system.elastic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.system.elastic.domain.Goods;
import com.system.elastic.mapper.GoodsMapper;
import com.system.elastic.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author Admin
* @description 针对表【goods】的数据库操作Service实现
* @createDate 2024-12-19 14:26:47
*/
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods>
    implements GoodsService{

    @Autowired
    private GoodsMapper goodsMapper;
    /**
     * @return
     */
    @Override
    public Integer selectCount() {
        QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
        goodsQueryWrapper.eq("status","2").ge("seckill_end",new Date())
                .ge("seckill_num",0);
        Long number = goodsMapper.selectCount(goodsQueryWrapper);
        return Math.toIntExact(number);
    }
    @Override
    public List<Goods> queryList(int page, int size) {
        //分页
        Page<Goods> pageCondition = new Page<>(page, size);
        QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
        goodsQueryWrapper.eq("status","2").ge("seckill_end",new Date())
                .ge("seckill_num",0);
        Page<Goods> pageData = goodsMapper.selectPage(pageCondition,goodsQueryWrapper);
        List<Goods> records = pageData.getRecords();
        return records;
    }
}





